package user;

import book.BookList;
import operation.AddOperation;
import operation.IOPeration;

import java.util.Scanner;

public abstract class User {
    protected String name;
    protected String type;
    protected IOPeration[] ioPerations;
    public abstract int menu();
    public User(String name, String type) {
        this.name = name;
        this.type = type;
    }

    public void doOperation(int choice, BookList bookList) {
        this.ioPerations[choice].work(bookList);
    }

    public int choiceOperation(IOPeration[] ioPerations) {
        Scanner in = new Scanner(System.in);
        char choice = in.next().charAt(0);
        in.nextLine();
        if('0' <= choice && choice <= ioPerations.length - 1 + '0') {
            return choice - '0';
        }
        System.out.println("输入错误请重新输入");
        /*
        *
            System.out.println("***********************");
            System.out.println("**     1. 查找图书    **");
            System.out.println("**     2. 新增图书    **");
            System.out.println("**     3. 删除图书    **");
            System.out.println("**     4. 显示图书    **");
            System.out.println("**   0. 退出图书系统   **");
            System.out.println("***********************");
            return choiceOperation(this.ioPerations);
        * ------
        * return this.menu();
        * 这两者等价
        * */
        return this.menu();
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }
}
